home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / ACC / OUTLINE.ACC / EXTEND.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  7.9 KB  |  377 lines

  1. /* extend.c - parse extend.sys file
  2.  * ====================================================================
  3.  * 900814 kbad
  4.  * 910626 cjg
  5.  * 921027 cjg
  6.  * 921207 cjg  Combine Bitmap and Outline fonts
  7.  * 921215 cjg  Did it!
  8.  *           Remove Bitmap and devices...
  9.  *
  10.  * NOTES:
  11.  *    1) The path must be the first item listed ( other than comments)
  12.  *    2) Fonts must be the last item.
  13.  *    3) Everything else can be mixed up in between.
  14.  *       ( Hows that for comments? )
  15.  */
  16.  
  17. /* INCLUDE
  18.  * ====================================================================
  19.  */
  20. #include <sys\gemskel.h>
  21.  
  22. #include "country.h" 
  23. #include "fonthead.h"
  24.  
  25. #include "lex.h"
  26. #include "fileio.h"
  27. #include "fsmio.h"
  28.  
  29.  
  30. /* DEFINES
  31.  * ====================================================================
  32.  */
  33. #define NO_FONT        0
  34. #define NORMAL_FONT    1
  35.  
  36.  
  37.  
  38. /* EXTERNS
  39.  * ====================================================================
  40.  */
  41. extern  Token lookahead;
  42.  
  43.  
  44. /* PROTOTYPES
  45.  * ====================================================================
  46.  */
  47. int    GetSYSPath( char *sysfile, char *path );
  48.  
  49. void    skipequal( void );
  50. void    fonts( void );
  51.  
  52.  
  53. /* GLOBALS
  54.  * ====================================================================
  55.  */
  56. struct stat statbuf;
  57. int    drv;
  58. char    Drive;
  59.  
  60.  
  61. /* isdir()
  62.  * ====================================================================
  63.  */
  64. int
  65. isdir( struct stat *s )
  66. {
  67.     return (s->st_mode & S_IFDIR );
  68. }
  69.  
  70.  
  71.  
  72.  
  73. /* GetSYSPath()
  74.  * ====================================================================
  75.  * Get the Paths for the EXTEND.SYS
  76.  */
  77. int
  78. GetSYSPath( char *sysfile, char *path )
  79. {
  80.     long len;
  81.  
  82.     /* Get the Bootup Device - It's either 'C' or 'A' */
  83.     Supexec( GetBootDrive );
  84.     drv = BootDrive;
  85.     Drive = BootDrive + 'A';
  86.     path[0] = Drive;   
  87.  
  88.     errno = 0;
  89.     xopen( sysfile );
  90.  
  91.     if( errno )
  92.     {
  93.        /* Error - No SYS file */
  94.        return( errno );
  95.     }
  96.     else
  97.     {
  98.        /* Found the SYS FILE */
  99.        lookahead = NO_TOKEN;
  100.        
  101.        /* Check for the PATH line at the top of the file. */
  102.        if( !match(PATH) )
  103.        {
  104.        /* Error: No Path line at the top of the SYS file */
  105.        xclose();     
  106.        return( 1 );
  107.        }
  108.        
  109.        skipequal();
  110.  
  111.        /* Check for the PATH itself at the top of the file.*/
  112.        if( match(PATHSPEC) )
  113.        {
  114.           /* Found the PATH */
  115.       strncpy( path, yytext, yyleng );
  116.       len = yyleng-1;
  117.       if( path[len] != '\\' ) ++len;
  118.       path[len] = '\0';
  119.       if( len > 2 )    /* below code fails for items like 'f:'*/
  120.       {
  121.         if( !stat( path, &statbuf) )
  122.             errno = (isdir(&statbuf)) ? 0 : ENOTDIR;
  123.         if( errno )
  124.         {
  125.           /* Error Parsing the path */    
  126.           xclose();
  127.           return( errno );
  128.         }
  129.       }  
  130.           
  131.        }
  132.        else
  133.        {
  134.           /* Error parsing the PATH */
  135.       xclose();
  136.       return( 1 );
  137.        }
  138.     }
  139.     xclose();
  140.     return( 0 );
  141. }
  142.  
  143.  
  144.  
  145.  
  146. /* parse_extend()
  147.  * ====================================================================
  148.  * Parse the EXTEND.SYS file to get the fonts...
  149.  * ANother routine is used to parse and get the cache settings etc...
  150.  * IN: int skip        0 - Don't skip anything, parse everything.
  151.  *                Used during a rez change or boot-up
  152.  *            1 - Skip parsing the path. Used during a 
  153.  *                directory change.
  154.  */
  155. int
  156. parse_extend( int skip )
  157. {
  158.     errno = 0;
  159.     xopen( ExtendPath );
  160.  
  161.     /* Check to see if the file 'EXTEND.SYS' exists.
  162.      */
  163.     if( errno )
  164.     {
  165.         /* NO- Its NOT HERE!!! */
  166.     /* There are NO Active Outline Fonts */
  167.         if( !skip )    
  168.         {
  169.            sprintf( Current.FontPath, "%c:", Drive );
  170.            
  171.          /* set some defaults here ONLY when we are supposed
  172.           * to parse EVERYTHING. This way when we are only 
  173.           * switching directories, the current values are 
  174.           * NOT affected.
  175.           */
  176.        Current.SpeedoCacheSize = 100L;    /* Set to 100K */
  177.        Current.BitMapCacheSize = 100L;
  178.        Current.speedo_percent  = 5;    /* Set to 50% */
  179.            Current.point_size[0] = 10;
  180.         }     
  181.     return( errno );
  182.     }
  183.  
  184.     if( !skip )
  185.     {
  186.        strcpy( Current.FontPath, OutlinePath );
  187.        Current.SpeedoCacheSize = 0L;
  188.        Current.BitMapCacheSize = 0L;
  189.        Current.speedo_percent = 5;    /* 50% */
  190.        Current.Width = 0;
  191.        Current.point_size[0] = 10;
  192.        strupr( &Current.FontPath[0] );
  193.     }
  194.  
  195.     lookahead = NO_TOKEN;
  196.  
  197.     skipequal();
  198.     match(PATH);
  199.     skipequal();
  200.     match(PATHSPEC);
  201.  
  202.     advance();
  203.  
  204.     while( !match(EOI) )
  205.     {
  206.     if( match(BITCACHE) )
  207.     {
  208.         skipequal();
  209.         
  210.         if( match(NUMBER) )
  211.         {
  212.             Current.BitMapCacheSize = atol( yytext )/1024L;
  213.         advance();
  214.         }
  215.     }
  216.     else if( match(FSMCACHE) )
  217.     {
  218.         skipequal();
  219.         
  220.         if( match(NUMBER) )
  221.         {
  222.             if( !skip )
  223.                 Current.SpeedoCacheSize = atol( yytext )/1024L;
  224.         advance();
  225.         }
  226.         
  227.         /* In case we have a 'comma'# 
  228.          * which is used to divide up the fsm_cache internally
  229.          * BUT, if we don't have the comma#, don't mess us up.
  230.          */
  231.         if( match( COMMA ) )
  232.         {
  233.             advance();
  234.             
  235.         if( match( NUMBER ) )
  236.         {
  237.            if( !skip )
  238.               Current.speedo_percent = atoi( yytext );
  239.            advance();
  240.         }        
  241.         }
  242.     }
  243.     else if( match(WIDTH) )
  244.     {
  245.         skipequal();
  246.         if( match(NUMBER) )
  247.         {
  248.             if( !skip )
  249.                Current.Width = atoi( yytext );
  250.         advance();
  251.         }
  252.     }
  253.     else
  254.          fonts();
  255.  
  256.     }
  257.     xclose();
  258.     return 0;
  259. }
  260.  
  261.  
  262.  
  263. /* skipequal()
  264.  * ====================================================================
  265.  * Advance past current token, and skip EQUAL token if one follows.
  266.  * If current token isn't followed by EQUAL, print an error message.
  267.  */
  268. void
  269. skipequal( void )
  270. {
  271.     advance();
  272.  
  273.     if( match(EQUAL) )
  274.     advance();
  275. }
  276.  
  277.  
  278.  
  279. /* fonts()
  280.  * ====================================================================
  281.  * Handle FONT and POINTS lines
  282.  */
  283. void
  284. fonts( void )
  285. {
  286.     char    fontpath[LINE_MAX];
  287.     char    fontname[LINE_MAX];
  288.     char    qfm[LINE_MAX];
  289.     char    *curpath, *ptext, *pqfm, *pname, *limit;
  290.     FON_PTR cfont;
  291.     int     flag = NORMAL_FONT;
  292.  
  293.     errno = 0;
  294.         
  295.     if( match( FONT ) )
  296.       flag = NORMAL_FONT;
  297.     else
  298.       flag = NO_FONT;
  299.  
  300.     if( flag )
  301.     {
  302.     skipequal();
  303.  
  304.     /* Set fontname to next token,
  305.      * and set current font path to fsmpath\fontname
  306.      * If the font doesn't exist, set curpath to NULL,
  307.      * and cfont to NULL.
  308.      * and print an error.
  309.      */
  310.     curpath = NULL;
  311.     cfont   = NULL;
  312.     if( match(PATHSPEC) )
  313.     {
  314.         ptext = yytext;
  315.         pname = fontname;
  316.         pqfm = NULL;
  317.         limit = yytext + yyleng;
  318.         while( ptext < limit )
  319.         {
  320.         if( isfilechar(*ptext) )
  321.             *pname++ = *ptext++;
  322.         else
  323.         {
  324.             strncpy( qfm, ptext, limit - ptext );
  325.             qfm[limit-ptext] = '\0';
  326.             if( strcmp(".spd", qfm) == 0 )
  327.             pqfm = qfm;
  328.             break;
  329.         }
  330.         }
  331.         if( pqfm )
  332.         {
  333.         *pname = '\0';
  334.         sprintf( fontpath, "%s\\%s.spd", OutlinePath, fontname );
  335.         /* stat() returns a zero is found, -1 if not 
  336.          * So, curpath contains the name ( with path ) of the
  337.          * font that we'll need to pass to sel_fsm_font()
  338.          * so that we can get the font name etc. and add
  339.          * it to the font list as an active font.
  340.          */
  341.         if( !stat(fontpath, &statbuf) )
  342.             curpath = fontpath;
  343.         if( curpath )
  344.         {
  345.             switch( flag )
  346.             {
  347.               case NORMAL_FONT:
  348.                                 cfont = get_single_fsm_font( fontname );
  349.                                 break;
  350.             }        
  351.         }    
  352.         }
  353.         advance();
  354.     }
  355.     /*
  356.      * If there's a POINTS line for this font, handle all point sizes.
  357.      */
  358.     if( match(POINTS) )
  359.     {
  360.         skipequal();
  361.  
  362.         while( match(NUMBER) )
  363.         {
  364.             /* set_font_pts() checks for cfont == NULL */
  365.             if( cfont )
  366.             set_font_pts( cfont, yytext );
  367.         advance();
  368.         if( match(COMMA) )
  369.             advance();
  370.         else
  371.             break;
  372.         }
  373.     }
  374.     }
  375. }
  376.  
  377.